module domain_mod

use global_mod

use utils_misc_mod, only: Critical_Error, ARROW_ERR_VAR_GET, ARROW_ERR_VAR_FIND

implicit none

type VarsObj
  real(kind=rlk), pointer :: rho(:) !< density
end type

integer(kind=ink), parameter :: ARROW_DEF_INT  = -200000000
real(kind=ink),    parameter :: ARROW_DEF_REAL = -200000000.0 

integer(kind=ink), parameter :: ARROW_VAR_RHO = 1

interface Var_Get
  module procedure Var_Get_i
end interface

type(VarsObj) :: vars

contains

subroutine Vars_Create(ncells, nnodes)
  integer(kind=ink), intent(in) :: ncells
  integer(kind=ink), intent(in) :: nnodes
  allocate(vars%rho(ncells))
  vars%rho = ARROW_DEF_REAL
end subroutine Vars_Create

integer(kind=ink) function Var_Find(varname) result(ivar)
  character(len=*), intent(in) :: varname
  select case(varname)
    case("rho")
      ivar = ARROW_VAR_RHO
    case default
      call Critical_Error(ARROW_ERR_VAR_FIND, "Var_Find")
  end select
end function Var_Find

function Var_Get_i(ivar) result(pvar)
  integer(kind=ink), intent(in) :: ivar
  real(kind=rlk), pointer :: pvar(:)
  select case (ivar)
    case(ARROW_VAR_RHO)
      pvar => vars%rho
    case default
      call Critical_Error(ARROW_ERR_VAR_GET, "Var_Get")
  end select
end function Var_Get_i

end module domain_mod